package cn.ryh.redis.singleredis.controller;

import cn.ryh.redis.entity.User;
import cn.ryh.redis.singleredis.service.RedisUserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName RedisUserController
 * @Description redis测试缓存Controller
 * @Author RaoYH
 */
@RestController
@RequestMapping(value = "/redisUserController")
public class RedisUserController {

    @Resource
    private RedisUserService redisUserService;

    @RequestMapping(value = "/getUser")
    public User getUser(Integer id) {
        User user = redisUserService.findUserById(id);
        return user;
    }

    @RequestMapping(value = "/redisCacheFindById")
    public void redisCacheFindById(){

        User loaded = redisUserService.redisCacheFindById(27);
        System.out.println("loaded="+loaded);
        User cached = redisUserService.redisCacheFindById(27);
        System.out.println("cached="+cached);
        loaded = redisUserService.redisCacheFindById(1);
        System.out.println("loaded2="+loaded);

    }
    @RequestMapping(value = "/redisCacheDelById")
    public void redisCacheDelById(Integer id){
        redisUserService.redisCacheDelById(27);
    }
}
